<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="项目名" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目代号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目代号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="票据号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入票据号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="状态" prop="status">-->
      <!--        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.purchase_status"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="项目状态" prop="projectStatus">-->
      <!--        <el-select v-model="queryParams.projectStatus" placeholder="请选择项目状态" clearable>-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.project_status"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="projectClearanceList">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="项目名" align="center" prop="projectName"/>
      <el-table-column label="项目代号" align="center" prop="projectCode"/>
      <el-table-column label="票据号" align="center" prop="number"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="清仓时间" align="center" prop="clearTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.clearTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作员" align="center" prop="operName"/>
<!--      <el-table-column label="备注" align="center" prop="remark"/>-->
<!--      <el-table-column label="状态" align="center" prop="status">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.purchase_status" :value="scope.row.status"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="项目状态" align="center" prop="projectStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_status" :value="scope.row.projectStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['purchase:projectClearance:edit']"
          >清库存
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetails(scope.row)"
            v-hasPermi="['purchase:projectClearance:detail']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改单据主表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="6">
            <el-form-item label="项目名:" prop="projectName">
              <span>{{ form.projectName }}</span>
              <!--              <el-input v-model="form.projectName" placeholder="请输入项目名"/>-->
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目代号:" prop="projectCode">
              <span>{{ form.projectCode }}</span>
              <!--              <el-input v-model="form.projectCode" placeholder="请输入项目代号"/>-->
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="票据号:" prop="number">
              <span>{{ form.number }}</span>
              <!--              <el-input v-model="form.number" placeholder="请输入票据号"/>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10" class="mb8">
          <el-col :span="6">
            <el-form-item label="创建时间:" prop="operTime">
              <span>{{parseTime(form.createTime)}}</span>
              <!--              <el-date-picker clearable-->
              <!--                              v-model="form.operTime"-->

              <!--                              type="date"-->
              <!--                              value-format="yyyy-MM-dd"-->
              <!--                              placeholder="请选择出入库时间"-->
              <!--              >-->
              <!--              </el-date-picker>-->
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="10" class="mb8">
          <div style="width: 100%;max-height:450px;overflow: auto;text-align: center">
            <el-table :data="tableData" border>
              <el-table-column label="物品名称" width="150" fixed>
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入物品名称" v-model="scope.row.inventoryName"></el-input>-->
                  <span>{{ scope.row.inventoryName }}</span>
                </template>
              </el-table-column>
              <el-table-column label="物品规格" fixed>
                <template slot-scope="scope">
                  <!--                <el-input placeholder="请输入物品规格" v-model="scope.row.inventorySpecifications"></el-input>-->
                  <span>{{ scope.row.inventorySpecifications }}</span>
                </template>
              </el-table-column>
              <el-table-column label="供应商" fixed>
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入供应商" v-model="scope.row.supply"></el-input>-->
                  <span>{{ scope.row.supply }}</span>
                </template>
              </el-table-column>
              <el-table-column label="wbs编码">
                <template slot-scope="scope">
    <!--          <el-input placeholder="请输入wbs编码" v-model="scope.row.wbs"></el-input>-->
                  <span>{{scope.row.wbs}}</span>
                </template>
              </el-table-column>
              <!--              <el-table-column label="备注">-->
              <!--                <template slot-scope="scope">-->
              <!--                  <el-input placeholder="请输入备注" v-model="scope.row.remark"></el-input>-->
              <!--                  &lt;!&ndash;                <span>{{scope.row.remark}}</span>&ndash;&gt;-->
              <!--                </template>-->
              <!--              </el-table-column>-->
<!--              <el-table-column label="待采购数量">-->
<!--                <template slot-scope="scope">-->
<!--                  &lt;!&ndash;                  <el-input placeholder="请输入待采购数量" v-model="scope.row.advancePurchaseNum"></el-input>&ndash;&gt;-->
<!--                  <span>{{ scope.row.advancePurchaseNum }}</span>-->
<!--                </template>-->
<!--              </el-table-column>-->
<!--              <el-table-column label="总库可用数量">-->
<!--                <template slot-scope="scope">-->
<!--                  &lt;!&ndash;                  <el-input placeholder="请输入备注" v-model="scope.row.advancePurchaseNum"></el-input>&ndash;&gt;-->
<!--                  <span>{{ scope.row.usableNum }}</span>-->
<!--                </template>-->
<!--              </el-table-column>-->
              <el-table-column label="实际采购数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入采购数量" v-model="scope.row.actualPurchaseNum"></el-input>-->
                  <span>{{ scope.row.actualPurchaseNum }}</span>
                </template>
              </el-table-column>
<!--              <el-table-column label="发货状态">-->
<!--                <template slot-scope="scope">-->
<!--                    <span v-for="(item) in dict.type.shipping_status" v-if="scope.row.shippingStatus === item.value">-->
<!--                    {{ item.label }}-->
<!--                  </span>-->
<!--                </template>-->
<!--              </el-table-column>-->
              <!--              <el-table-column label="采购员">-->
              <!--                <template slot-scope="scope">-->
              <!--                  &lt;!&ndash;                <el-input placeholder="请输入姓名" v-model="scope.row.name"></el-input>&ndash;&gt;-->
              <!--                  <span>{{ scope.row.purchaseMan }}</span>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <el-table-column label="入库数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入合格数量" v-model="scope.row.qualifiedNum"></el-input>-->
                  <span>{{ scope.row.havaInNum === null ? 0 : scope.row.havaInNum }}</span>
                  <!--                  <span>{{ scope.row.inNum }}</span>-->
                </template>
              </el-table-column>
              <el-table-column label="出库数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入合格数量" v-model="scope.row.qualifiedNum"></el-input>-->
                  <!--                  <span>{{ scope.row.haveOutNum }}</span>-->
                  <span>{{ scope.row.havaOutNum === null ? 0 : scope.row.havaOutNum }}</span>
                </template>
              </el-table-column>
              <el-table-column label="可转移数量">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.operNumber" :readonly="true"/>
<!--                  <el-input-number placeholder="请输入可转移数量" v-model="scope.row.operNumber"-->
<!--                                   style="width: 50px;text-align: left;padding: 0px 0px"-->
<!--                                   size="small" :controls="false"-->
<!--                                   :max="scope.row.inNum-scope.row.outNum" :min="0"></el-input-number>-->
<!--                  &lt;!&ndash;                  <span>{{ scope.row.qualifiedNum }}</span>&ndash;&gt;&ndash;&gt;-->
                </template>
              </el-table-column>
              <el-table-column label="转移数量">
                <template slot-scope="scope">
                  <!--                  <el-input placeholder="请输入合格数量" v-model="scope.row.qualifiedNum"></el-input>-->
                  <!--                  <span>{{ scope.row.haveOutNum }}</span>-->
                  <span>{{ scope.row.transferNum === null ? 0 : scope.row.transferNum }}</span>
                </template>
              </el-table-column>
              <!--              <el-table-column label="出库仓库">-->
              <!--                <template slot-scope="scope">-->
              <!--                  <el-input placeholder="请输入入库仓库" v-model="scope.row.outDepot"></el-input>-->
              <!--                  &lt;!&ndash;                  <span>{{ scope.row.qualifiedNum }}</span>&ndash;&gt;&ndash;&gt;-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="出库操作员">-->
              <!--                <template slot-scope="scope">-->
              <!--                  <el-input placeholder="请输入操作员" v-model="scope.row.outOperateMan"></el-input>-->
              <!--                  &lt;!&ndash;                  <span>{{ scope.row.qualifiedNum }}</span>&ndash;&gt;&ndash;&gt;-->
              <!--                </template>-->
              <!--              </el-table-column>-->
              <!--              <el-table-column label="操作" fixed="right">-->
              <!--                <template slot-scope="scope">-->
              <!--                  <el-button @click="outRow(scope.row)">出库</el-button>-->
              <!--                </template>-->
              <!--              </el-table-column>-->
            </el-table>
          </div>
        </el-row>

        <el-form-item label="附件名称">
          <file-upload v-model="form.fileName"/>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--    详情弹窗-->
    <el-dialog :title="title" :visible.sync="details" width="1200px">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="6">
            <el-form-item label="项目名: " prop="projectName">
              <!--              <el-input v-model="form.projectName" placeholder="请输入项目名"/>-->
              <span>{{ form.projectName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目代号: " prop="projectCode">
              <!--              <el-input v-model="form.projectCode" placeholder="请输入项目代号"/>-->
              <span>{{ form.projectCode }}</span>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="票据号: " prop="number">
              <!--              <el-input v-model="form.number" placeholder="请输入票据号"/>-->
              <span>{{ form.number }}</span>

            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10" class="mb8" v-show="false">
          <div style="width: 100%;overflow-x: auto;text-align: center">
            <el-table :data="tableData" border ref="report-table">
              <el-table-column label="项目名称">
                <el-table-column prop="inventoryName" label="物品名称" width="150"></el-table-column>
              </el-table-column>

              <el-table-column :label="form.projectName">
                <el-table-column prop="inventorySpecifications" label="物品规格" width="150"></el-table-column>

              </el-table-column>

              <el-table-column label="项目代号">
                <el-table-column prop="supply" label="供应商"></el-table-column>
              </el-table-column>

              <el-table-column :label="form.projectCode">
                <el-table-column prop="wbs" label="wbs编码"></el-table-column>
<!--                <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>-->
              </el-table-column>

              <el-table-column label="总库可用数量">
<!--                <el-table-column prop="usableNum" label="总库可用数量"></el-table-column>-->
              </el-table-column>

              <el-table-column :label="form.contractNumber">
                <el-table-column prop="actualPurchaseNum" label="实际采购数量"></el-table-column>
<!--                <el-table-column label="发货状态">-->
<!--                  <template slot-scope="scope">-->
<!--                    <span v-for="(item) in dict.type.shipping_status" v-if="scope.row.shippingStatus === item.value">-->
<!--                    {{ item.label }}-->
<!--                  </span>-->
<!--                  </template>-->
<!--                </el-table-column>-->
              </el-table-column>
              <el-table-column label="票据号">
                <el-table-column label="入库数量">
                  <template slot-scope="scope">
                    <span>{{ scope.row.havaInNum === null ? 0 :  scope.row.havaInNum}}</span>
                  </template>
                </el-table-column>
              </el-table-column>
              <el-table-column :label="form.number">
                <el-table-column label="出库数量">
                  <template slot-scope="scope">
                    <span>{{ scope.row.havaOutNum === null ? 0 :  scope.row.havaOutNum}}</span>
                  </template>
                </el-table-column>
                <el-table-column label="转移数量">
                  <template slot-scope="scope">
                    <span>{{ scope.row.transferNum === null ? 0 :  scope.row.transferNum}}</span>
                  </template>
                </el-table-column>
              </el-table-column>
            </el-table>
          </div>
        </el-row>
        <el-row :gutter="10" class="mb8">
          <div style="width: 100%;overflow-x: auto;text-align: center">
            <el-table :data="tableData" border>
              <el-table-column prop="inventoryName" label="物品名称" width="150"></el-table-column>
              <el-table-column prop="inventorySpecifications" label="物品规格" width="150"></el-table-column>
              <el-table-column prop="supply" label="供应商"></el-table-column>
              <el-table-column prop="wbs" label="wbs编码"></el-table-column>
<!--              <el-table-column prop="advancePurchaseNum" label="待采购数量"></el-table-column>-->
<!--              <el-table-column prop="usableNum" label="总库可用数量"></el-table-column>-->
              <el-table-column prop="actualPurchaseNum" label="实际采购数量"></el-table-column>
<!--              <el-table-column label="发货状态">-->
<!--                <template slot-scope="scope">-->
<!--                    <span v-for="(item) in dict.type.shipping_status" v-if="scope.row.shippingStatus === item.value">-->
<!--                    {{ item.label }}-->
<!--                  </span>-->
<!--                </template>-->
<!--              </el-table-column>-->
              <el-table-column label="入库数量">
                <template slot-scope="scope">
                  <span>{{ scope.row.havaInNum === null ? 0 :  scope.row.havaInNum}}</span>
                </template>
              </el-table-column>
              <el-table-column label="出库数量">
                <template slot-scope="scope">
                  <span>{{ scope.row.havaOutNum === null ? 0 :  scope.row.havaOutNum}}</span>
                </template>
              </el-table-column>
              <el-table-column label="转移数量">
                <template slot-scope="scope">
                  <span>{{ scope.row.transferNum === null ? 0 :  scope.row.transferNum}}</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-row>

      </el-form>
      <div slot="footer" style="text-align: center">
        <el-button type="success" size="medium" @click="exportExcel">导出</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRyDepotHead,
  dataprocess,
  getRyDepotHead,
  delRyDepotHead,
  addRyDepotHead,
  updateRyDepotHead
} from '@/api/purchase/ryDepotHead'
import * as XLSX from 'xlsx/xlsx.mjs'
import * as FileSaver from 'file-saver'
import axios from 'axios'
import {$message} from 'element-ui'
import {getToken} from '@/utils/auth'
import {blobValidate} from '@/utils/ruoyi'
import {listProjectClearance} from '@/api/purchase/projectClearance'
import request from "@/utils/request";

export default {

  name: 'projectClearance',
  dicts: ['project_status', 'purchase_status', 'return_status', 'shipping_status', 'retransmission_status'],
  data() {
    return {
      ip: 'http://localhost:8080',
      count: 0,
      uploadData: [], //文件数据
      fileData: '', // 保存选择的文件
      list: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 单据主表表格数据
      projectClearanceList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectCode: null,
        contractNumber: null,
        number: null,
        status: null,
        projectStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      tableData: [],
      details: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      listProjectClearance(this.queryParams).then(response => {
        this.projectClearanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      console.log('执行了')
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        projectCode: null,
        contractNumber: null,
        type: null,
        subType: null,
        defaultNumber: null,
        number: null,
        createTime: null,
        operTime: null,
        organId: null,
        billType: null,
        remark: null,
        fileName: null,
        salesMan: null,
        status: null,
        projectStatus: null,
        linkNumber: null,
        tenantId: null,
        delFlag: null,
        tableData: []
      }
      this.tableData = []
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map(item => item.id)
    //   this.single = selection.length !== 1
    //   this.multiple = !selection.length
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加单据主表'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      let that = this
      console.log(id)

      return request({
        url: '/purchase/projectClearance/selectByDepotId/' + id,
        method: 'get'
      }).then(function(res) {
        // this.open = true
        that.open = true;
        that.title = '清理库存';
        that.form = res.data;
        for (let i = 0; i < res.data.tableData.length; i++) {
          console.log(res.data.tableData[i].operNumber)
          res.data.tableData[i].operNumber = res.data.tableData[i].havaInNum - res.data.tableData[i].havaOutNum - res.data.tableData[i].transferNum
          console.log(res.data.tableData[i].operNumber)
          that.tableData.push(res.data.tableData[i])
        }
      })

      // getRyDepotHead(id).then(response => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = '修改单据主表'
      // })
    },
    /** 提交按钮 */
    submitForm() {
      let that = this
      this.form.tableData = this.tableData
      console.log(this.form)
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            return request({
              url: '/infc/editProjectClearance',
              method: 'post',
              data: this.form
            }).then(function(res) {
              that.$message({
                showClose: 3000,
                message: '修改成功',
                type: 'success'
              })
              that.open = false
              that.getList()
            })
          } else {
            return request({
              url: '/infc/addDepotHeadAndDetail',
              method: 'post',
              data: this.form
            }).then(function(res) {
              that.$message({
                showClose: 3000,
                message: '添加成功',
                duration: 0,
                type: 'success'
              })
              that.open = false
              that.getList()
            })
          }
        }
      })
    },
    //详情弹窗
    handleDetails(row) {
      this.reset()
      const id = row.id || this.ids
      let that = this
      console.log(id)

      return request({
        url: '/purchase/projectClearance/selectByDepotId/' + id,
        method: 'get'
      }).then(function(res) {
        that.details = true
        that.title = '详情';

        that.form = res.data;
        that.tableData = res.data.tableData
        console.log(res.data)
      })

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除单据主表编号为"' + ids + '"的数据项？').then(function () {
        return delRyDepotHead(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('purchase/ryDepotHead/export', {
        ...this.queryParams
      }, `ryDepotHead_${new Date().getTime()}.xlsx`)
    },

    readExcel(files) {
      this.count += 1
      if (this.count % 3 === 1) {
        console.log('zhiixng')
        this.fileData = files // 保存当前选择文件
        let that = this
        // console.log(files.file.originFileObj)
        let type = files.file.name.split('.')
        if (!files) {
          //如果没有文件
          return false
        } else if (type[type.length - 1] !== 'xlsx' && type[type.length - 1] !== 'xls' && type[type.length - 1] !== 'et') {
          this.$message.error('上传格式不正确，请上传xls或者xlsx格式')
          return false
        }
        const fileReader = new FileReader()
        // 如果为原生 input 则应是 files[0]
        fileReader.readAsBinaryString(files.file.originFileObj)
        fileReader.onload = ev => {// 异步执行
          try {
            const data = ev.target.result
            const workbook = XLSX.read(data, {
              type: 'binary'
            })
            const wsname = workbook.SheetNames[0] //取第一张表
            const ws = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]) //生成json表格内容
            that.uploadData = [] //清空接收数据

            for (let i = 6; i < ws.length; i++) {
              let arr = {}
              //   arr.wbs = ''
              for (const key in ws[i]) {
                switch (key) {
                  case 'LIST  明 细 表':
                    arr.name = ws[i][key].toUpperCase().replace(/\s*/g, '')
                    break
                  case '__EMPTY_1':
                    arr.drawing = ws[i][key]
                    break
                  case '__EMPTY_2':
                    arr.spec = ws[i][key].toUpperCase().replace(/\s*/g, '')
                    break
                  case '__EMPTY_3':
                    arr.supplier = ws[i][key]
                    break
                  case '__EMPTY_4':
                    arr.number = ws[i][key]
                    break
                  case '__EMPTY_6':
                    arr.wbs = ws[i][key]
                    break
                }
              }
              if (arr.name !== undefined) {
                this.list.push(arr)
                // if (this.list.length === 0) {
                //   console.log('dfgfg' )
                //   this.list.push(arr)
                // } else {
                //   console.log('-->'+this.list.length);
                //   let list11 = this.list;
                //   for (let j = 0; j < this.list.length; j++) {
                //     console.log("jjj-->"+j)
                //     console.log(this.list[j].spec)
                //     console.log(arr.spec)
                //     console.log(this.list[j].name)
                //     console.log(arr.name)
                //     if (this.list[j].spec === arr.spec && this.list[j].name === arr.name) {
                //
                //         if (this.list[j].spec === arr.spec && this.list[j].name === arr.name) {
                //           console.log('重复了')
                //           this.list[j].number += arr.number;
                //           length = null;
                //           break;
                //       }
                //     } else {
                //       console.log('xinzenghl')
                //       this.list.push(arr);
                //       length = null;
                //       break
                //     }
                //   }
                // }
              }
            }
            console.log(this.list)
          } catch (ev) {
            console.log('报错')
            return false
          }
        }
      }

    },
    aa() {
      let that = this
      console.log('执行了')
      axios({
        url: this.ip + '/infc/dataProcess',
        method: 'post',
        // responseType: 'json',
        contentType: 'application/json,charset=UTF-8 ',
        data: this.list
      }).then(function (res) {
        console.log(res)
        if (res.data.code === '001') {
          console.log('报错了')
          that.$message({
            showClose: true,
            message: res.data.msg,
            duration: 0,
            type: 'warning'
          })
        } else {
          that.tableData = res.data.data
        }
      })
    },
    //删除行
    outRow(data) {
      console.log(data)
      axios({
        url: this.ip + '/infc/oneOutDetail',
        method: 'post',
        // responseType: 'json',
        contentType: 'application/json,charset=UTF-8 ',
        data: data
      }).then(function (res) {
        console.log(res)
      })
    },
    //增加行
    addRow() {
      let newRow = {name: '', psd: '', age: ''}
      this.tableData.splice(this.tableData.length, 0, newRow)
    },
    exportExcel() {
      try {
        const $e = this.$refs['report-table'].$el
        let $table = $e.querySelector('.el-table__fixed')
        if (!$table) {
          $table = $e
        }

        const wb = XLSX.utils.table_to_book($table, {raw: true})
        const wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: true, type: 'array'})
        FileSaver.saveAs(
          new Blob([wbout], {type: 'application/octet-stream'}),
          `项目清仓详情.xlsx`,
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.error(e)
      }
    }
  }
}
</script>
